/*
 * @file      WindowsRulesTest.cpp
 * @brief     WindowsRulesTest is a test file to WindowsRules interface.
 *
 * @author    Franco Riberi
 * @email     fgriberi AT gmail.com
 *
 * Contents:  Source file.
 *
 * System:    titere: Target Ideal TEmperature Rna Expression
 * Language:  C++
 *
 * @date February 3, 2015
 *
 * Copyright (C) 2015 Franco Riberi, FuDePAN
 *
 * This file is part of titere.
 *
 * titere is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * titere is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with titere. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <biopp/biopp.h>
#include <gtest/gtest.h>

#define private public

#include "titere/Exceptions.h"
#include "titere/PredicateRule.h"
#include "titere/WindowsRules.h"

using namespace NSTitere;

//-------------------------------------------------------------------------------
// StartWithAdenineOrUracil Rule
//-------------------------------------------------------------------------------
TEST(PredicateRuleTestSuite, StartWithAdenineOrUracil)
{
    const biopp::NucSequence sequence1("UGCAUUCUGGACAGGCGGCCU");
    IPredicateRule* const rule = new StartWithAdenineOrUracil();
    bool rulePassed = rule->checkRule(sequence1);
    EXPECT_TRUE(rulePassed);

    const biopp::NucSequence sequence2("AAGCAUGGAAGCGCU");
    rulePassed = rule->checkRule(sequence2);
    EXPECT_TRUE(rulePassed);
    delete rule;
}

TEST(PredicateRuleTestSuite, StartWithAdenineOrUracilBeginsWithOtherNucleotid)
{
    const biopp::NucSequence sequence("GCAUGGAAGCGCU");
    IPredicateRule* const rule = new StartWithAdenineOrUracil();
    const bool rulePassed = rule->checkRule(sequence);
    EXPECT_FALSE(rulePassed);
    delete rule;
}


//-------------------------------------------------------------------------------
// FirstEigthNucleotide Rule
//-------------------------------------------------------------------------------
TEST(PredicateRuleTestSuite, FirstEigthNucleotideWithUracil)
{
    const biopp::NucSequence sequence1("UGCAUUCUGGACAGGCGGCCU");
    IPredicateRule* const rule = new FirstEigthNucleotide();
    bool rulePassed = rule->checkRule(sequence1);
    EXPECT_TRUE(rulePassed);

    const biopp::NucSequence sequence2("AGCAACAGGACAGGCGGCCU");
    rulePassed = rule->checkRule(sequence2);
    EXPECT_TRUE(rulePassed);

    const biopp::NucSequence sequence3("GAAAAAAGCAACAGGACAGGCGGCCU");
    rulePassed = rule->checkRule(sequence3);
    EXPECT_TRUE(rulePassed);

    delete rule;
}

TEST(PredicateRuleTestSuite, FirstEigthNucleotideHaveNotAorU)
{
    const biopp::NucSequence sequence("GUGCACCGUCUGGACAGGCGGCCU");
    IPredicateRule* const rule = new FirstEigthNucleotide();
    bool rulePassed = rule->checkRule(sequence);
    EXPECT_FALSE(rulePassed);

    const biopp::NucSequence sequence2("GGCAACAGGACAGGCGGCCU");
    rulePassed = rule->checkRule(sequence2);
    EXPECT_FALSE(rulePassed);
    delete rule;
}


//-------------------------------------------------------------------------------
// NucleotidNineteen Rule
//-------------------------------------------------------------------------------
TEST(PredicateRuleTestSuite, NucleotidNineteen)
{
    const biopp::NucSequence sequence("GUGCACCGUCUGGACAGGGGGCCU");
    IPredicateRule* const rule = new NucleotidNineteen();
    bool rulePassed = rule->checkRule(sequence);
    EXPECT_TRUE(rulePassed);

    const biopp::NucSequence sequence2("GUGCACCGUCUGGACAGGCCGCCU");
    rulePassed = rule->checkRule(sequence2);
    EXPECT_TRUE(rulePassed);

    delete rule;

}

TEST(PredicateRuleTestSuite, NucleotidNineteenFailed)
{
    const biopp::NucSequence sequence1("GCGGCCU");
    IPredicateRule* const rule = new NucleotidNineteen();
    EXPECT_THROW(rule->checkRule(sequence1), InvalidPosition);

    const biopp::NucSequence sequence2("GUGCACCGUCUGGACAGGAAGCCU");
    const bool rulePassed = rule->checkRule(sequence2);
    EXPECT_FALSE(rulePassed);
    delete rule;
}